package com.wzq.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.wzq.app.R;
import com.wzq.app.api.Api;
import com.wzq.app.api.ApiResponseCode;
import com.wzq.app.base.BaseActivity;
import com.wzq.app.manager.UserManager;
import com.wzq.app.model.BaseModel;
import com.wzq.app.model.EvaModel;
import com.wzq.app.model.RateModel;
import com.wzq.app.utils.ToastUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @ProjectName: 2021WZQ
 * @Package: com.wzq.app.ui
 * @ClassName: EvaDetailActivity
 * @Description: java类作用描述
 * @UpdateUser: 更新者：
 * @UpdateDate: 2021-03-07 0:36
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class EvaDetailActivity extends BaseActivity {
    private static final String TAG = "EvaDetailActivity";

    EvaModel evaModel;
    @BindView(R.id.head_left)
    TextView headLeft;
    @BindView(R.id.head_left_text)
    TextView headLeftText;
    @BindView(R.id.number)
    TextView number;

    String con = "";
    @BindView(R.id.content)
    TextView content;

    @Override
    public int getLayoutId() {
        return R.layout.rating_detail_activity;
    }

    @Override
    public void configView() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        evaModel = (EvaModel) bundle.getSerializable("eva");
        headLeftText.setText("评价详情");
        Log.d(TAG, evaModel.toString());
        number.setText(evaModel.getGoal() + "");
        String[] cho = evaModel.getChoose().split(",");
        int[] choin = new int[cho.length];
        for (int i = 0; i < cho.length; i++) {
            Log.d(TAG, "cho[" + i + "]:" + cho[i]);
            choin[i] = Integer.valueOf(cho[i]);
            Log.d(TAG, "choin[" + i + "]:" + choin[i]);
        }
        headLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        getData(choin);
    }

    public void getData(int[] a) {
        Call<BaseModel<List<RateModel>>> call = Api.getInstance().service.getRateList(UserManager.getInstance().getUser().getType());
        call.enqueue(new Callback<BaseModel<List<RateModel>>>() {
            @Override
            public void onResponse(Call<BaseModel<List<RateModel>>> call, Response<BaseModel<List<RateModel>>> response) {
                if (response.isSuccessful()) {
                    BaseModel<List<RateModel>> baseModel = response.body();
                    if (baseModel.code == ApiResponseCode.RESPHONE_OK) {
                        List<RateModel> list = baseModel.obj;
                        for (int i = 0; i < list.size(); i++) {
                            String e = "";
                            switch (a[i]) {
                                case 0:
                                    e = list.get(i).getEvaA();
                                    break;
                                case 1:
                                    e = list.get(i).getEvaB();
                                    break;
                                case 2:
                                    e = list.get(i).getEvaC();
                                    break;
                                case 3:
                                    e = list.get(i).getEvaD();
                                    break;
                            }
                            Log.d(TAG, list.get(i).getEvaName() + ":" + e);
                            con += list.get(i).getEvaName() + " : " + e + "\n\n";
                        }
                        content.setText(con);
                    } else {
                        ToastUtils.showToast(mContext, "获取评分方式失败，请检查网络");
                    }

                }
            }

            @Override
            public void onFailure(Call<BaseModel<List<RateModel>>> call, Throwable t) {
                ToastUtils.showToast(mContext, "获取评分方式失败，请检查网络");
            }
        });
    }

    @Override
    public void requestData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
